#include <iostream>
#include <string>

#include <algorithm>
#include <vector>
using namespace std;

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        int maxpos = nums.size() - 1;
        int count = 0;
        sort(nums.begin(), nums.end());
        while (maxpos > 1)
        {
            int left = 0, right = maxpos - 1;
            while (left < right)
            {
                if (nums[left] + nums[right] > nums[maxpos])
                {
                    count += right - left;
                    right--;
                }
                else left++;
            }
            maxpos--;
        }
        return count;
    }
};

int main()
{
    Solution s;
    vector<int> tri;
    tri.push_back(4);
    tri.push_back(2);
    tri.push_back(3);
    tri.push_back(4);
    int number=s.triangleNumber(tri);
    cout << number << endl;

    return 0;
}
